//
//  BaseViewController.swift
//  nimabi
//
//  Created by danny on 15/6/24.
//  Copyright © 2015年 DannyLiu. All rights reserved.
//

import UIKit

class BaseViewController: UITableViewController,VisitorViewDelegate {


    
        var userlogon = (sharedUserAccount != nil)
    
    
    
        var visitView: VisitorView?
        override func loadView(){
            
            
            userlogon ? super.loadView() : setupVisitorView()
        }
       
    
    ///  创建访客试图
    ///
    ///  @return
    private func setupVisitorView(){
        
        // 替换根试图,系统默认会在tabbar和navbar之间创建一个view
        visitView = VisitorView()
        visitView?.delegate = self
        view = visitView
        
        
        // 添加导航栏按钮
        navigationItem.leftBarButtonItem = UIBarButtonItem(title: "注册", style: UIBarButtonItemStyle.Plain, target: self, action: "visitorRegisterButtonClicked")
        navigationItem.rightBarButtonItem = UIBarButtonItem(title: "登录", style: UIBarButtonItemStyle.Plain, target: self, action: "visitorLoginButtonClicked")
        
    }


    // MARK: - 访客视图协议方法
    func visitorRegisterButtonClicked() {
        print("注册")
    }
    
    func visitorLoginButtonClicked() {
        
        let vc = OAuthViewController()
        let nav = UINavigationController(rootViewController: vc)
        
        presentViewController(nav, animated: true ,completion: nil)
        
        
        
        
    }
    
    
}
